package ru.ncedu.java.vlku.hrs.uil.cmd;

import ru.ncedu.java.vlku.hrs.bll.HRSManager;
import ru.ncedu.java.vlku.hrs.bll.HRSManagerFactory;
import ru.ncedu.java.vlku.hrs.model.CustomerAccount;

import java.util.List;

public class GetCustomerAccount implements Command {
    // get customer_account by id <id>
    // get customer_account by name <name>
    @Override
    public void execute(String[] args) {
        if (args.length != 5 || !args[2].equals("by"))
            throw new IllegalArgumentException();
        HRSManager manager = HRSManagerFactory.getInstance().getHRSManager();
        if (args[3].equals("id")) {
            Long id = Long.parseLong(args[4]);
            CustomerAccount ca = manager.getCustomerAccountById(id);
            System.out.println("Id\tName\tEmail\tPassword\tPhone");
            System.out.println(ca.getId() + "\t" + ca.getName() + "\t" + ca.getEmail() + "\t" +
                    ca.getPassword() + "\t" + ca.getPhone());
        } else if (args[3].equals("name")) {
            List<CustomerAccount> cas = manager.getCustomerAccountsWithName(args[4]);
            System.out.println("Id\tName\tEmail\tPassword\tPhone");
            for (int i = 0; i < cas.size(); i++)
                System.out.println(cas.get(i).getId() + "\t" + cas.get(i).getName() + "\t" + cas.get(i).getEmail() + "\t" +
                        cas.get(i).getPassword() + "\t" + cas.get(i).getPhone());
        } else
            throw new IllegalArgumentException();
   }
}
